<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>sessionStorage.html</title>
    <script type="text/javascript" src="js/jquery-1.7.2.js"></script>
</head>
<body>
<button id="save">save</button><br><br>
<button id="read">read</button><br><br>
<button id="delete">delete</button><br><br>
<button id="clear">clear</button><br><br>
</body>
<script type="text/javascript">
    let p = {name: '张三', age: 18}
    $("#save").click(function () {
        sessionStorage.setItem('msg', 'Hello!!!');
        sessionStorage.setItem('msg2', 666);
        // sessionStorage.setItem('person', p);
        sessionStorage.setItem('person', JSON.stringify(p));
        return false;
    });
    $("#read").click(function () {
        // let msg = sessionStorage.getItem('msg');
        // let msg2 = sessionStorage.getItem('msg2');
        let person = sessionStorage.getItem('person');
        // let msgItem = JSON.parse(msg);
        // let msg2Item = JSON.parse(msg2);
        let personItem = JSON.parse(person);
        // console.log(msgItem);
        // console.log(msg2Item);
        console.log(personItem);
        return false;
    });
    $("#delete").click(function () {
        sessionStorage.removeItem('msg');
        return false;
    });
    $("#clear").click(function () {
        sessionStorage.clear();
        return false;
    });
</script>
</html>